package com.youlian.cloud.user.config.aspect;

import com.youlian.cloud.log.asepct.CatAspect;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

/**
 * service层AOP拦截器定义
 *
 * @author Liuhx
 * @create 2018-06-14 12:01
 * @email liuhx@elab-plus.com
 **/

@Aspect
@EnableAspectJAutoProxy
@Configuration
public class ServiceAspectBean {

    @Bean
    public CatAspect getCatAspect() {
        CatAspect catAspect = new CatAspect();
        return catAspect;
    }

    @Around(value = "execution(* com.youlian.cloud.user.service..*(..))")
    public Object around(ProceedingJoinPoint pjp) throws Exception {
        if(pjp.getSignature().getName().equals("excel")){
            try {
                return pjp.proceed();
            } catch (Throwable throwable) {
                System.out.println(throwable.getMessage());
            }
        }
        return getCatAspect().aroundMethod(pjp);
    }
}
